package model;

import controller.ConfigurationController;
import util.Date;

public class RegistrationValidateRegistrationDate extends RegistrationValidator {

	private final Date REGISTRATION_START = new Date();
	private final Date REGISTRATION_END= new Date();

	public RegistrationValidateRegistrationDate(RegistrationValidationBehavior registrationValidationBehavior) {
		super(registrationValidationBehavior);
		try {
			REGISTRATION_START.setDate(ConfigurationController.instance().getProperty("registration.startDate"));
			REGISTRATION_END.setDate(ConfigurationController.instance().getProperty("registration.endDate"));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void validate(Registration registration) throws Exception {
		super.validate(registration);
		if (registration.getRegistrationDate().compareTo(REGISTRATION_START) < 0) {
			throw new Exception("SchoolRegistration period starts at " + REGISTRATION_START);
		} else if (registration.getRegistrationDate().compareTo(REGISTRATION_END) > 0) {
			throw new Exception("SchoolRegistration period ends at " + REGISTRATION_END);
		}

	}
}
